<template>
  <div class="echart" ref="mychart" id="mychart" :style="{ width: '100%', height: '400px' }"></div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: 'testView',
  data() {
    return {
      option: {
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
        },
        yAxis: {
          type: 'value',
        },
        series: [
          {
            data: [120, 200, 150, 80, 70, 110, 130],
            type: 'bar',
          },
        ],
      },
    }
  },
  mounted() {
    this.initChart()
  },
  methods: {
    initChart() {
      // 获取 DOM 元素，用于初始化图表
      const myChart = echarts.init(this.$refs.mychart)

      // 设置图表的配置项
      myChart.setOption(this.option)

      // 监听窗口调整大小，调整图表的大小
      window.addEventListener('resize', () => {
        myChart.resize()
      })
    },
  },
}
</script>

<style scoped>
/* 设置图表容器的样式 */
.echart {
  width: 100%;
  height: 400px;
}
</style>
